package MySQLConnection;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class Conn {
    Connection con;
    public static String user;
    public static String password;
    public Connection getConnection() {
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
            System.out.println("数据库驱动加载成功！");
        } catch (ClassNotFoundException e) {
            System.out.println("驱动加载异常。。。 e = "+e);
        }
        user = "root";
        password = "123456";
        try{
            con = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/crm?characterEncoding=utf8&useSSL=false&allowPublicKeyRetrieval=true",user,password);
            System.out.println("数据库连接成功！");
        }catch(SQLException e) {
            System.out.println("数据库连接失败！"+e);
        }
        return con;
    }

    public static void main(String[] args) {
        Conn conn = new Conn();
        conn.getConnection();
    }
}
